package com.usian.admin.task;

import com.usian.admin.feign.MediaFeign;
import com.usian.admin.service.NewsAutoScanService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import groovy.util.logging.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Log4j2
public class WeMediaNewsAutoScanJob {
    @Autowired
    private MediaFeign wemediaFeign;
    @Autowired
    private NewsAutoScanService service;

    /**
     * 每天0点执行一次
     *
     * @param param
     * @return
     * @throws Exception
     */
    @XxlJob("AutoScanJob2307")//jobhandler
    public ReturnT<String> hello(String param) throws Exception {
        List<Long> releaseIdList = wemediaFeign.findRelease();//查询出状态为8且发布时间到了的新闻id
        if (null != releaseIdList && !releaseIdList.isEmpty()) {
            for (Long id : releaseIdList) {
                service.autoScan(id);
            }
        }
        return ReturnT.SUCCESS;
    }
}
